package Offer;

/**
 * 链表中倒数第k个节点
 * @author 是阿秋啊
 * @date 2022/04/09 22:06
 **/
public class Num22 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        if (head == null) {
            return null;
        }
        ListNode fast = head;
        for (int i = 0; i < k; i++) {
            fast = fast.next;
        }
        ListNode ret = head;
        while (fast != null) {
            ret = ret.next;
            fast = fast.next;
        }
        return ret;
    }
}
